package guoanmaker.operator.business.service;

import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.springframework.stereotype.Service;

import guoanmaker.operator.business.model.OperatorLuckdraw;
import guoanmaker.operator.business.model.OperatorLuckdrawRecord;
import guoanmaker.operator.business.modelnobind.OperatorLuckRecordAndUser;
import guoanmaker.operator.business.modelnobind.operatorEnlistDetails;
import guoanmaker.operator.business.repository.OperatorLuckdrawRecordRepository;

@Service
public class OperatorLuckdrawRecordService implements OperatorLuckdrawRecordServiceInterface {

	private final  OperatorLuckdrawRecordRepository operatorLuckdrawRecordRepository;
	@PersistenceContext
	private EntityManager manager;
	public OperatorLuckdrawRecordService(OperatorLuckdrawRecordRepository operatorLuckdrawRecordRepository){
		this.operatorLuckdrawRecordRepository=operatorLuckdrawRecordRepository;
	}

	@Override
	public List<OperatorLuckRecordAndUser> getOperatorLuckdrawRecord(String id) {
		String sql = "SELECT pu.username, pu.email, olr.luckdraw_type, olr.record_time FROM t_personal_user pu,t_operator_luckdraw_record olr WHERE pu.id=olr.user_id and olr.activity_id=:id ";
		Query query = manager.createNativeQuery(sql, OperatorLuckRecordAndUser.class);
		query.setParameter("id", id);
		List<OperatorLuckRecordAndUser> enlist = (List<OperatorLuckRecordAndUser>) query.getResultList();
		return enlist;
	}
	
	
	
	
}
